package com.cn.zsc.controller;

import com.cn.zsc.service.OrderService;
import com.cn.zsc.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@RestController
public class OrderConller {

    @Autowired
    private OrderService orderService;

    @GetMapping("handleOrder")
    public String handleOrder(Integer orderId){
        try{
            int result = orderService.handleOrder(orderId);
            if (result == 0) return "success";
            return "fail";
        }catch (Exception ex){
            return "fail";
        }
    }

    @Autowired
    private PaymentService paymentService;

    @GetMapping("creatPayment")
    public String creatPayment(int orderId){
        int payment = paymentService.payment(1, orderId, new BigDecimal(10));
        return payment+"";
    }
}
